#pragma once

#include <string>
#include "RenderableObject.h"
#include <d3d9.h>
#include <d3dx9.h>
#include <vector>


class CGraphicsController;

///////////////////////////////////////////////////////////////////////////////

struct CAnimatedImageVertex
{
   CAnimatedImageVertex(float _x, float _y, float _u, float _v)
         : x(_x), y(_y), z(0), u(_u), v(_v)
   {
   }

   float x, y, z;
   float u, v;

   static DWORD FVF;
};

///////////////////////////////////////////////////////////////////////////////

class AnimatedImage : public IRenderableObject
{
private:
   CGraphicsController& m_graphicsController;
   IDirect3DTexture9* m_imageTexture;
   IDirect3DVertexBuffer9* m_vertices;

   float m_frameWidth;
   float m_frameHeight;
   float m_texFrameWidth;
   float m_texFrameHeight;
   bool m_transparent;

   UINT m_animationFrame;

   D3DXMATRIX m_mtxWorld;
   std::vector<D3DXMATRIX> m_mtxTex;

public:
   AnimatedImage(CGraphicsController& graphicsController,
                 const std::wstring& fileName,
                 UINT numFrames,
                 UINT frameWidth,
                 UINT frameHeight,
                 bool transparent = false);
   ~AnimatedImage(void);

   void setPosition(float x, float y);

   float getWidth() const;
   float getHeight() const;

   void advanceFrame();

   void render(CViewFrustrum& frustrum, IDirect3DDevice9& d3Device);

   bool is3D() const {return false;}
};
